import cks from 'js-cookie';
import lexicon from '../lexicon/index';

const TokenKey: string = lexicon.cookies.tokenKey;
const UserNoKey: string = lexicon.cookies.userNoKey;
const UserNameKey: string = lexicon.cookies.userNameKey;
const UserIdKey: string = lexicon.cookies.userIdKey;
const DBNameKey: string = lexicon.cookies.dbNameKey;
const LanguageKey: string = lexicon.cookies.languageKey;

const getToken = (): string => {
  return cks.get(TokenKey) || 'undefined';
};

const setToken = (token: string): string => {
  return cks.set(TokenKey, token) || 'undefined';
};
const removeToken = (): void => {
  return cks.remove(TokenKey);
};
const getUserNo = (): string => {
  return cks.get(UserNoKey) || 'undefined';
};
const setUserNo = (userNo: string): string => {
  return cks.set(UserNoKey, userNo) || 'undefined';
};

const removeUserNo = (): void => {
  return cks.remove(UserNoKey);
};

const getUserName = (): string => {
  return cks.get(UserNameKey) || 'undefined';
};
const setUserName = (userName: string): string => {
  return cks.set(UserNameKey, userName) || 'undefined';
};
const removeUserName = (): void => {
  return cks.remove(UserNameKey);
};

const getUserID = (): string => {
  return cks.get(UserIdKey) || 'undefined';
};
const setUserID = (userID: string): string => {
  return cks.set(UserIdKey, userID) || 'undefined';
};
const removeUserID = (): void => {
  return cks.remove(UserIdKey);
};

const getDBName = (): string => {
  return cks.get(DBNameKey) || 'undefined';
};
const setDBName = (dbName: string): string => {
  return cks.set(DBNameKey, dbName) || 'undefined';
};
const removeDBName = (): void => {
  return cks.remove(DBNameKey);
};

const getLanguage = (): string => {
  return cks.get(LanguageKey) || 'undefined';
};
const setLanguage = (language: string): string => {
  return cks.set(LanguageKey, language) || 'undefined';
};
const removeLanguage = (): void => {
  return cks.remove(LanguageKey);
};
const logOut = (): void => {
  removeToken();
  removeUserNo();
  removeUserName();
  removeUserID();
  removeDBName();
};

const removeCookies = (): void => {
  removeToken();
  removeUserNo();
  removeUserName();
  removeUserID();
  removeDBName();
};

export default {
  getToken,
  setToken,
  removeToken,
  getUserNo,
  setUserNo,
  removeUserNo,
  getUserName,
  setUserName,
  removeUserName,
  getUserID,
  setUserID,
  removeUserID,
  getDBName,
  setDBName,
  removeDBName,
  getLanguage,
  setLanguage,
  removeLanguage,
  logOut,
  removeCookies
};
